// Ground.cpp
#include "Ground.h"
#include <windows.h>
#include <gl/GL.h>
#include <gl/GLU.h>

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

namespace ANvDbg
{
    static GLuint ground;

    void Ground::Init()
    {
        ground = glGenLists(1);
        glNewList(ground, GL_COMPILE);
        glBegin(GL_QUADS);
        for (int i = 0; i < 20; ++i)
        {

            float z = 100.f - i * 10.f;
            for (int j = 0; j < 20; ++j)
            {
                float x = j * 10.f - 100.f;
                if ((i % 2) ^ (j % 2))
                {
                    glColor4ub(41, 41, 41, 255);
                }
                else
                {
                    glColor4ub(200, 200, 200, 255);
                }
                glVertex3f(x, -2.f, z);
                glVertex3f(x + 10.f, -2.f, z);
                glVertex3f(x + 10.f, -2.f, z - 10.f);
                glVertex3f(x, -2.f, z - 10.f);
            }
        }
        glEnd();
        glEndList();
    }

    void Ground::Render()
    {
        glEnable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
        glDisable(GL_TEXTURE_2D);
        glPushMatrix();
        glCallList(ground);
        glPopMatrix();
    }
}
